<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax_demo</title>
</head>
<body>
<button type="button" onclick="loadDoc()">获取我收藏的 CD</button>
<table id="demo"></table>
<script>
//加载收藏
function loadDoc()
{
    var xhttp=new XMLHttpRequest();//创建请求
    xhttp.onreadystatechange=function()
    {
        if(this.readyState==4&&this.status==200)
            display(this);
    };
    xhttp.open("GET","http://localhost:8888/cd_catalog.xml",true);
    xhttp.send();
}
//显示收到的回复
function displayRes() {
    var i;
    var xmlDoc = xml.responseXML;
    var table="<tr><th>Artist</th><th>Title</th></tr>";
    var x = xmlDoc.getElementsByTagName("CD");
    for (i = 0; i <x.length; i++) {
        table += "<tr><td>" +
            x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
            "</td><td>" +
            x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
            "</td></tr>";
    }
    document.getElementById("demo").innerHTML = table;
}
</script>
</body>
</html>